package singleton.seriable;

import singleton.seriable.SeriableSingleton;

import java.io.*;

/**
 * @author Feng
 * @date 2019/3/10 15:53
 */
public class BrokenSeriablesSingleton {
    public static void main(String[] args) {
        SeriableSingleton seriableSingleton = null;
        SeriableSingleton seriableSingleton1 = SeriableSingleton.getInstance();

        FileOutputStream fileOutputStream = null;
        try{
            fileOutputStream = new FileOutputStream("SeriableSingleton.obj");
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
            objectOutputStream.writeObject(seriableSingleton1);
            fileOutputStream.close();
            objectOutputStream.close();

            FileInputStream fileInputStream = new FileInputStream("SeriableSingleton.obj");
            ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
            seriableSingleton = (SeriableSingleton) objectInputStream.readObject();
            fileInputStream.close();
            objectInputStream.close();

            System.out.println(seriableSingleton);
            System.out.println(seriableSingleton1);
            System.out.println(seriableSingleton == seriableSingleton1);

        }
        catch (Exception e){
            e.printStackTrace();
        }
    }
}
